package com.wangp.mywrite.coding;

/**
 * @author tooStronger
 * @date 2022/7/30
 */
public class LargestComponentSize {

    public int largestComponentSize(int[] nums) {
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length && i != j; j++) {
                if(isCommonFactor(nums[i],nums[j])){
                    count++;
                }
            }
        }
        return count;
    }

    private boolean isCommonFactor(int num1 , int num2) {
        int min = Math.min(num1,num2);
        int max = Math.max(num1,num2);

        for (int i = 2; i <= min; i++) {
            if(min % i  == 0 && max % i ==0){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        LargestComponentSize largestComponentSize = new LargestComponentSize();
        int[] arr = {4, 6, 15, 35};
//        int[] arr = {20,50,9,63};
        System.out.println(largestComponentSize.largestComponentSize(arr));
    }
}
